/*
 * 测试环境 - 本地服务器
 * @author li.xiaomei
 * @date 2016-12-15
 */

//依赖模块
var fs = require('fs');
var express = require('express');
var app = express();
var router = require('../middleware/router');
var webpackMiddleware = require('../middleware/webpack')

//变量
var port = global.think_config.port;

module.exports = function(){

  //webpack 本地开发环境
  var devMiddleware = webpackMiddleware.dev(),
      hotMiddleware = webpackMiddleware.hot();
  app.use(devMiddleware);
  app.use(hotMiddleware);

  //设置虚拟目录
  app.use(express.static(process.cwd(), {
    //directory: true
  }));

  //在应用中加载路由模块
  app.use(router);

  //启动本地服务器
  app.listen(port, function(err){
    if (err) {
      console.log('【error】:')
      console.log(err)
      return;
    }
    console.log('Listening at http://localhost:' +port+ '\n')
  });
}
